package com.xmsx.back.mapper.admin;

import com.xmsx.back.pojo.Job;
import com.xmsx.back.pojo.Organization;
import com.xmsx.back.pojo.Recruitment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrganizationMapper {

    /**
     * 获取某个单位信息的所有数据
     * @param id
     * @return
     */
    @Select("select * from organization where id = #{id}")
    Organization getById(@Param("id") int id);

    /**
     * 插入单位信息
     * @param organization
     */
    @Insert("insert into organization values(" +
            "#{organization.id}, " +
            "#{organization.orgName}, " +
            "#{organization.orgRegion}, " +
            "#{organization.grassrootType}, " +
            "#{organization.defenseMilitary}, " +
            "#{organization.collegeInstitute}, " +
            "#{organization.keyNational}, " +
            "#{organization.keyMedical}, " +
            "#{organization.keyFinancial}, " +
            "#{organization.keyMedia}, " +
            "#{organization.office}, " +
            "#{organization.keySoftware}, " +
            "#{organization.informSafety})")
    void setOrganization(@Param("organization") Organization organization);

    /**
     * 修改单位信息
     * @param organization
     */
    @Insert("update organization set " +
            "org_name = #{organization.orgName}, " +
            "org_region = #{organization.orgRegion}, " +
            "grassroot_type = #{organization.grassrootType}, " +
            "defense_military = #{organization.defenseMilitary}, " +
            "college_institute = #{organization.collegeInstitute}, " +
            "key_national = #{organization.keyNational}, " +
            "key_medical = #{organization.keyMedical}, " +
            "key_financial = #{organization.keyFinancial}, " +
            "key_media = #{organization.keyMedia}, " +
            "office = #{organization.office}, " +
            "key_software = #{organization.keySoftware}, " +
            "inform_safety = #{organization.informSafety} " +
            "where id = #{organization.id}")
    void updateOrganization(@Param("organization") Organization organization);

    /**
     * 删除单位信息
     * @param id
     */
    @Select("delete from organization where id=#{id}")
    void deleteOrganization(@Param("id") int id);

    /**
     * 统计记录数
     * @return
     */
    @Select("select count(1) from organization")
    long count();

    @Select("select * from organization limit #{page},#{size}")
    List<Organization> findByPager(Map<String, Object> params);

    /**
     * 按关键词按页查询
     *
     * @param params
     * @return
     */
    @Select("select * from organization where org_name like concat('%', #{keyword}, '%') order by id asc limit #{page},#{size}")
    List<Organization> findByKeywordByPager(Map<String, Object> params);

    /**
     * 按关键词模糊查询
     *
     * @param keyword
     * @return
     */
    @Select("select count(1) from organization where org_name like concat('%', #{keyword}, '%')")
    long countByKeyword(String keyword);
}
